<?php

if (!eregi("modules.php", $_SERVER['PHP_SELF'])) {
    die ("You can't access this file directly...");
}

require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
get_lang($module_name);

if (file_exists("".$datafold."/config_".$module_name.".php")) { 
    @require_once ("".$datafold."/config_".$module_name.".php"); 
} 

$shownumeric = 1;
$font1= "<font  style=\"font-style: normal; font-variant: normal; font-weight: bold; font-size: 10pt; font-family: Arial; cursor: hand; text-decoration: none\">";
$font2= "<font  style=\"font-style: normal; font-variant: normal; font-weight: regular; font-size: 10pt; font-family: Arial; cursor: hand; text-decoration: none\">";
function getparent($parentid,$title) {
    global $prefix,$db;
        $sql = "select cid, title, parentid from ".$prefix."_vanban_theloai where cid=$parentid";
        $res = $db->sql_query($sql);
        $row = $db->sql_fetchrow($res);
        $cid = $row[cid];
        $ptitle = $row[title];
        $pparentid = $row[parentid];
        mysql_free_result($result);
        if ($ptitle!="") $title=$ptitle." | ".$title;
        if ($pparentid!=0) {
        $title=getparent($pparentid,$title);
        }
        return $title;
}
function menu($c_cid) {
  global $prefix, $db, $module_name, $font1;
        /****************************************/
        $c_cid = intval($c_cid);
        echo "<DIV align=right><form name=\"gocat\"><table><tr><td>"
        ."<select name=\"cat\" OnChange=\"location.href=gocat.cat.options[selectedIndex].value\">";
        $sql = "select cid, title, parentid from ".$prefix."_vanban_theloai order by parentid,title";
        $res = $db->sql_query($sql);
        
        echo "<option value=\"\">"._CATSELECTED."</option>";
        while($row = $db->sql_fetchrow($res)) {
        $cid = $row[cid];
        $cat_title = $row[title];
        $parentid = $row[parentid];
                if ($parentid!=0) $cat_title=getparent($parentid,$cat_title);
        $sql2 = "SELECT cid  FROM ".$prefix."_vanban_theloai WHERE parentid = '$cid'";
        $resnum = $db->sql_query($sql2);
        if ($numrows = $db->sql_numrows($resnum) > 0) {
        $links = "cat";
         }
        else {
        $links = "showcat";
         }
        echo "<option value=\"modules.php?name=$module_name&go=$links&cid=$cid\"> $cat_title</option>";
        }
        echo "<option value=\"modules.php?name=$module_name\">"._PAGESHOME."</option>";
        echo "</select></td></tr></table></form></DIV>";
        
   }
 function theloai($cid){  
 	global $prefix, $db, $module_name, $font1;   
 	        
        $sql = "SELECT title FROM ".$prefix."_vanban_theloai WHERE cid='$cid'";
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $c_title = $row[title];
        echo "<hr>";
        echo "<center>$font1". _THUOC.": $c_title </font><br><br></center>";
        
        
}
// Phan cuoi trang
function footmenu() {
        global $module_name, $banquyen;
        echo "<br><hr>";
        /****************************************/
        echo "<center><b><a href=\"javascript:history.go(-1)\">"._PAGEBACK."</a> | <a href=modules.php?name=$module_name>"._PAGEHOME."</a> | <a href=#>"._PAGETOP."</a></b></center><br>";
        /****************************************/
}

function links($sc_cid) {
        global $prefix, $db, $module_name;
        
        $sc_cid = intval($sc_cid);
        $sql = "SELECT cid  FROM ".$prefix."_vanban_theloai WHERE parentid = '$sc_cid'";
        $resnum = $db->sql_query($sql);
        if ($numrows = $db->sql_numrows($resnum) > 0) {
        $cat_links = "cat"; }
        else {
        $cat_links = "showcat"; }
        echo "<a style=\"TEXT-DECORATION: none\" href=\"modules.php?name=$module_name&go=$cat_links&cid=$sc_cid\">";
}

function main() {
    global $db,$font1,$font2,$nukeurl,$vprint, $prefix, $module_name, $multilingual, $currentlang, $newhome,$banquyen, $newhomenum, $shownumeric,$vnocat,$outpage;
    
    include("header.php");
    	menu($c_cid);
       /****************************************/
    if ($multilingual == 1) {
        $querylang = "AND (alanguage='$currentlang' OR alanguage='')";
    } else {
        $querylang = "";
    }
    
    
    $sql = "SELECT cid, title, FROM ".$prefix."_vanban_theloai WHERE parentid='0' $querylang";
    $result = $db->sql_query($sql);
    while ($row = $db->sql_fetchrow($result)) {
    $cid = $row[cid];
    $title = $row[title];
    
    
    
    echo "<img border=\"1\" src=\"modules/$module_name/images/cat_pic.gif\" width=\"10\" height=\"14\"> ";
    links($cid);
    echo "<b>$title </b></a>";
        }
     if ($newhome == 1) {
    $sql3 = "SELECT pid, title, hometext,url, UNIX_TIMESTAMP(date) as postdate FROM ".$prefix."_vanban WHERE cid !='0' AND active = '1' ORDER BY pid DESC LIMIT $newhomenum";
    $result3 = $db->sql_query($sql3);
    if ($numrows = $db->sql_numrows($result3) > 0) {
    echo "<table border=\"0\" bordercolor=\"#008080\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";
    echo "<tr><td>";
    echo "<table border=\"0\" cellpadding=\"0\" bordercolor=\"#008080\" cellspacing=\"0\" width=\"100%\"><tr><td>";
    echo "$font1"._NEWPAGES."</font><br><br>";
    echo "</td></tr></table>";
    echo "</td></tr>";
    echo "<tr><td>";
    echo "<table border=\"1\" style=\"BORDER-COLLAPSE: collapse\"  borderColor=\"#008000\" cellpadding=\"2\" cellspacing=\"0\" width=\"100%\">";
    echo "<tr bgcolor=\"#008000\" align=\"center\"><td>$font1"._SOHIEU."</font></td><td>$font1"._TOMTAT."</font></td><td>$font1"._SENDDATE."</font></td></tr><tr>";
    while ($row = $db->sql_fetchrow($result3)) {
    $p_pid = $row[pid];
    $p_title = $row[title];
    $p_hometext = $row[hometext];
    $p_hometext = stripslashes(check_html($p_hometext, nohtml));
    $url = $row[url];
    $p_date = date("d/m/Y", $row["postdate"]);
    
    echo "<td width=\"20%\"><a style=\"TEXT-DECORATION: none\" href=modules.php?name=$module_name&go=page&pid=$p_pid>$font1 $p_title</font></a> &nbsp</td>";
    echo "<td width=\"60%\">$font2$p_hometext &nbsp</font><br>";
    if(!$url==""){
    echo "<p align=\"right\">".$font2._DOWLOAD."</font>:";
    echo "<a  style=\"TEXT-DECORATION: none\" href=\"$url\"><img src=\"modules/$module_name/images/dowload.bmp\" border=\"0\" ></a> ";
     }else echo "<p align=\"right\">&nbsp";
    if (!$p_pid=="") {
    	$pid=intval($p_pid);
    echo "&nbsp&nbsp".$font2._PRINTV."</font>:";
    echo "<a href=\"#\" onClick=\"MM_openBrWindow('modules.php?name=$module_name&file=printv&pid=$pid','','scrollbars=yes,width=640,height=500')\" onMouseOut=\"window.status=''; return true;\" onMouseOver=\"window.status='"._PRINTV."'; return true;\"><img src=\"images/print.gif\" border=\"0\" alt=\""._PRINTV."\" title=\""._PRINTV."\" width=\"16\" height=\"16\"></a>\n";
        }
   echo "</p></td>";
    echo "<td width=\"15%\" align=\"right\">$font2$p_date &nbsp</font></td>";
    echo "</tr>";
      }
    echo "</table></td></tr></table>";
    }
    
    }
    
    echo "<br><br>";
    if ($vnocat==1){
    	$pageout=$outpage;
    $sql4 = "SELECT pid, title, hometext, UNIX_TIMESTAMP(date) as postdate FROM ".$prefix."_vanban WHERE cid ='0' AND active = '1' ORDER BY pid DESC LIMIT $pageout";
    $result4 = $db->sql_query($sql4);
    if ($numrows = $db->sql_numrows($result4) > 0) {
    	    echo "$font1"._PAGESHOMECATS."</font><hr>";
    while ($row = $db->sql_fetchrow($result4)) {
    $p_pid = $row[pid];
    $p_title = $row[title];
    $p_hometext = $row[hometext];
    $p_hometext = stripslashes(check_html($p_hometext, nohtml));
    $p_date = date("d/m/Y", $row["postdate"]);
    echo "<img border=\"0\" src=\"modules/$module_name/images/page_pic.gif\" width=\"10\" height=\"14\"><b><a style=\"TEXT-DECORATION: none\" href=modules.php?name=$module_name&go=page&pid=$p_pid>$p_title</a></b><br><i>$p_hometext</i><br>"._SENDDATE.": $p_date<br><br>";
    }
    }}
    /****************************************/
    if ($shownumeric == 1) {
    echo "<br>";
    /****************************************/
    $num_cat = $db->sql_numrows($db->sql_query("SELECT cid FROM ".$prefix."_vanban_theloai"));
    $num_page = $db->sql_numrows($db->sql_query("SELECT pid FROM ".$prefix."_vanban WHERE active='1'"));
    echo "<center><hr>$font1"._ALLP."</font><b>$num_page</b>$font1 "._ALLP2." </font><b>$num_cat</b> $font1"._ALLP3."<br></font></center>";
     /****************************************/
    }

    include("footer.php");
}

// Danh sach tat ca cac chu de
function cat($cid) {
    global $db, $prefix, $module_name, $font1, $font2;
    $cid = intval($cid);
    include("header.php");
    menu($cid);
    /****************************************/
    echo "$font1"._VBCON."</font><br>";
    
    $sql = "SELECT cid, title, parentid FROM ".$prefix."_vanban_theloai WHERE parentid='$cid'";
    $result = $db->sql_query($sql);
    while ($row = $db->sql_fetchrow($result)) {
    $c_cid = $row[cid];
    $title = $row[title];
    $parentid = $row[parentid];
    
    echo "<img border=\"0\" src=\"modules/$module_name/images/cat_pic.gif\" width=\"10\" height=\"14\"> ";
    links($c_cid);
    echo "$font1 $title </font></a>";
       }
        echo "<br><br>";
        echo $font1._VBTHUOC."</font><br><br>";
    showcatcha($cid);
        echo "<br><br>";
    $sql4 = "SELECT pid, title, hometext, UNIX_TIMESTAMP(date) as postdate FROM ".$prefix."_vanban WHERE cid ='$cid' AND active = '1' ORDER BY pid DESC";
    $result4 = $db->sql_query($sql4);
    if ($numrows = $db->sql_numrows($result4) > 0) {
    echo "$font1"._PAGESHOMECAT."</font><hr>";
    while ($row = $db->sql_fetchrow($result4)) {
    $p_pid = intval($row[pid]);
    $p_title = $row[title];
    $p_hometext = $row[hometext];
    $p_hometext = stripslashes(check_html($p_hometext, nohtml));
    $p_date = date("d/m/Y", $row["postdate"]);
    echo "<img border=\"0\" src=\"modules/$module_name/images/page_pic.gif\" width=\"10\" height=\"14\"><b><a style=\"TEXT-DECORATION: none\" href=modules.php?name=$module_name&go=page&pid=$p_pid>$p_title</a></b><br><i>$p_hometext</i><br>"._SENDDATE.": $p_date<br><br>";
    }
    }
    /****************************************/
    footmenu();
    include("footer.php");
}

function showcat($cid) {
    global $db, $prefix, $module_name, $numpage, $pagenum, $font1, $font2;
    $cid = intval($cid);
    include("header.php");
    menu($cid);
    /****************************************/
    if ($pagenum == "") {
    $pagenum = 1 ;
    }
    $offset = ($pagenum-1) * $numpage;

    $sql = "SELECT pid, title, hometext, url, UNIX_TIMESTAMP(date) as postdate FROM ".$prefix."_vanban WHERE cid ='$cid' AND active = '1' ORDER BY pid DESC limit $offset, $numpage";
    $result = $db->sql_query($sql);
    echo"<br>";
    echo "<table border=\"1\" style=\"BORDER-COLLAPSE: collapse\"  borderColor=\"#008000\"   cellpadding=\"2\" cellspacing=\"0\" width=\"100%\">";
    echo "<tr bgcolor=\"#008000\"><td align=\"center\"><font size=\"2\">"._SOHIEU."</font></td><td align=\"center\"><font size=\"2\">"._TOMTAT."</font> </td><td align=\"center\"><font size=\"2\">"._SENDDATE."</font></td></tr><tr>";
    if ($numrows = $db->sql_numrows($result) > 0) {
    while ($row = $db->sql_fetchrow($result)) {
    $p_pid = intval($row[pid]);
    $p_title = $row[title];
    $p_hometext = $row[hometext];
    $p_hometext = stripslashes(check_html($p_hometext, nohtml));
    $p_date = date("d/m/Y", $row["postdate"]);
    $url = $row[url];    
     echo "<td width=\"20%\"><a style=\"TEXT-DECORATION: none\" href=modules.php?name=$module_name&go=page&pid=$p_pid>$font1 $p_title</font></a> &nbsp</td>";
    echo "<td width=\"60%\">$font2$p_hometext &nbsp</font><br>";
    if(!$url==""){
    echo "<p align=\"right\">".$font2._DOWLOAD."</font>:";
    echo "<a  style=\"TEXT-DECORATION: none\" href=\"$url\"><img src=\"modules/$module_name/images/dowload.bmp\" border=\"0\" ></a> ";
     }else echo "<p align=\"right\">&nbsp";
    if (!$p_pid=="") {
    	$pid=intval($p_pid);
    echo "&nbsp&nbsp".$font2._PRINTV."</font>:";
    echo "<a href=\"#\" onClick=\"MM_openBrWindow('modules.php?name=$module_name&file=printv&pid=$pid','','scrollbars=yes,width=640,height=500')\" onMouseOut=\"window.status=''; return true;\" onMouseOver=\"window.status='"._PRINTV."'; return true;\"><img src=\"images/print.gif\" border=\"0\" alt=\""._PRINTV."\" title=\""._PRINTV."\" width=\"16\" height=\"16\"></a>\n";
        }
   echo "</p></td>";
    echo "<td width=\"15%\" align=\"right\">$font2$p_date &nbsp</font></td>";
    echo "</tr>";
         
    }
    echo "</table>";
    
    }
    #START Page Numbers
    $sql_pn = "select pid from ".$prefix."_vanban where  cid ='$cid' AND active = '1'";
    $result_pn = $db->sql_query($sql_pn);
    $numstories = $db->sql_numrows($result_pn);
    @$numpages = ceil($numstories / $numpage);
    if ($numpages > 1) {
        /****************************************/
        echo "<center>" ;
        if ($pagenum > 1) {
            $prevpage = $pagenum - 1 ;
                        $leftarrow = "images/left.gif" ;
                echo "<a href=\"modules.php?name=$module_name&amp;go=showcat&amp;cid=$cid&amp;pagenum=$prevpage\">";
                echo "<img src=\"$leftarrow\" align=\"absmiddle\" border=\"0\" hspace=\"10\"></a>";

        }
        for ($i=1; $i < $numpages+1; $i++) {

            if ($i == $pagenum) {
                echo "<b>$i</b>";
            }
            else {
            $pagelink = 10;
            if (($i > $pagenum) AND ($i < $pagenum+$pagelink) OR ($i < $pagenum) AND ($i > $pagenum-$pagelink)) {
            echo " <a href=\"modules.php?name=$module_name&amp;go=showcat&amp;cid=$cid&amp;pagenum=$i\">$i</a> ";
            }
            if (($i == $numpages) AND ($pagenum < $numpages-$pagelink)){
            echo "... <a href=\"modules.php?name=$module_name&amp;go=showcat&amp;cid=$cid&amp;pagenum=$i\">$i</a>";
            }
            if (($i == 1) AND ($pagenum > 1+$pagelink)){
            echo "<a href=\"modules.php?name=$module_name&amp;go=showcat&amp;cid=$cid&amp;pagenum=$i\">$i</a> ...";
            }
            }
        }
        if ($pagenum < $numpages) {
            $nextpage = $pagenum + 1 ;
                        $rightarrow = "images/right.gif" ;
                echo "<a href=\"modules.php?name=$module_name&amp;go=showcat&amp;cid=$cid&amp;pagenum=$nextpage\">";
                echo "<img src=\"$rightarrow\" align=\"absmiddle\" border=\"0\" hspace=\"10\"></a>";
        }
        echo "</center>" ;
        /****************************************/
    }
    #END Page Numbers
    /****************************************/
    footmenu();
    include("footer.php");
}
function page($pid, $page=0) {
    global $page_title,$index, $hometext, $bodytext, $db, $prefix, $module_name, $admin, $pagecatlink, $pagecatnumlinc, $font1, $font2;
 
    $pid = intval($pid);
    if ($page == 0) {
    $db->sql_query("UPDATE ".$prefix."_vanban WHERE pid='$pid'");
    }
    $sql = "SELECT cid, title, hometext, bodytext, chuthe, nguoiky, url, UNIX_TIMESTAMP(date) as postdate  FROM ".$prefix."_vanban WHERE pid='$pid'";
    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrow($result);
    $cid = intval($row[cid]);
    $page_title = $row[title];
    $hometext = $row[hometext];
    $bodytext = $row[bodytext];
    $chuthe = $row[chuthe];
    $nguoiky = $row[nguoiky];
    $url = $row[url];
    $p_date = date("d/m/Y", $row["postdate"]);
    
    $contentpages = explode( "<!--pagebreak-->", $bodytext );
        $pageno = count($contentpages);
        if ( $page=="" || $page < 1 ) {
            $page = 1;
            }
        if ( $page > $pageno )
            $page = $pageno;
        $arrayelement = (int)$page;
        $arrayelement --;
    include("header.php");
     menu($cid);
     theloai($cid);
    /****************************************/
    
    if (!$bodytext==""){
    	$index=0;
    echo "<table border=\"1\" style=\"BORDER-COLLAPSE: collapse\"  borderColor=\"#008000\" cellpadding=\"2\" cellspacing=\"0\" width=\"100%\">";
    echo "<tr><td>";
    echo "$font2 $contentpages[$arrayelement]</font>";
    echo "</td></tr></table>";
    if ($pageno != 1) {
    echo "<hr>";
    }
        if($page >= $pageno) {
            $next_page = "";
        } else {
            $next_pagenumber = $page + 1;
            if ($page != 1) {
                $next_page .= "- ";
            }
            $next_page .= "<a style=\"TEXT-DECORATION: none\" href=\"modules.php?name=$module_name&go=page&pid=$pid&page=$next_pagenumber\"><b>"._NEXT."</b> ($next_pagenumber/$pageno)</a> <a href=\"modules.php?name=$module_name&go=page&pid=$pid&page=$next_pagenumber\"><img src=\"modules/$module_name/images/next_page.gif\" border=\"0\" alt=\""._NEXT."\" title=\""._NEXT."\"></a>";
        }
        if($page <= 1) {
            $previous_page = "";
        } else {
            $previous_pagenumber = $page - 1;
            $previous_page = "<a href=\"modules.php?name=$module_name&go=page&pid=$pid&page=$previous_pagenumber\"><img src=\"modules/$module_name/images/prev_page.gif\" border=\"0\" alt=\""._PREVIOUS."\" title=\""._PREVIOUS."\"></a> <a style=\"TEXT-DECORATION: none\" href=\"modules.php?name=$module_name&go=page&pid=$pid&page=$previous_pagenumber\"><b>"._PREVIOUS."</b> ($previous_pagenumber/$pageno)</a>";
        }
        echo "<center>$font2$previous_page $next_page</font></center>";
        }else{
        echo $font1._SOHIEU."</font>:";
    echo $font2 .$page_title."</font><br><br>";
        echo $font1._TOMTAT."</font>:";
        echo $font2 .$hometext."</font><br><br>";
        echo "$font1"._SENDDATE.": $p_date</font><br><br>";
        echo $font1._CHUTHE."</font>: ";
        echo $font2 .$chuthe."</font><br><br>";
        echo $font1._NGUOIKY."</font>: ";
        echo $font2 .$nguoiky."</font><br><br>";
        echo $font1._DOWLOAD."</font>:";
        echo "<a  style=\"TEXT-DECORATION: none\" href=\"$url\"><img src=\"modules/$module_name/images/dowload.bmp\" border=\"0\" ></a> ";
        }
        
    if (defined('IS_ADMMOD')) {
    echo "<hr><center><a href=admin/admin.php?op=pages_delit_page&pid=$pid>"._DELPAGE."</a> | <a href=admin/admin.php?op=vanban_edit_page&pid=$pid>"._EDITPAGE."</a> | <a href=admin/admin.php?op=pages_status_page&pid=$pid&act=off>"._OFFPAGE."</a></center>";
    }
    if ($pagecatlink == 1) {
    $sql2 = "SELECT pid, title FROM ".$prefix."_vanban WHERE cid='$cid' AND pid !='$pid' AND active = '1' LIMIT $pagecatnumlinc";
    $result2 = $db->sql_query($sql2);
    $num = $db->sql_numrows($result2);
    if ($num > 0) {
    echo "<br>$font1"._LINKPAGES."</font><br>";
    while ($row = $db->sql_fetchrow($result2)) {
    $l_pid = $row[pid];
    $l_title = $row[title];
    echo "<img border=\"0\" src=\"modules/$module_name/images/page_pic.gif\" width=\"10\" height=\"14\"> \n"
    ."<a style=\"TEXT-DECORATION: none\" href=modules.php?name=$module_name&go=page&pid=$l_pid><b>$l_title</b></a><br>";
    }
    }
    }
    /****************************************/
    footmenu();
    include("footer.php");
    }

    function showcatcha($cid) {
    global $db, $prefix, $module_name, $numpage, $pagenum, $font1, $font2;
    $cid = intval($cid);
   
    if ($pagenum == "") {
    $pagenum = 1 ;
    }
    $offset = ($pagenum-1) * $numpage;

    $sql = "SELECT pid, title, hometext, url, UNIX_TIMESTAMP(date) as postdate FROM ".$prefix."_vanban WHERE cid ='$cid' AND active = '1' ORDER BY pid DESC limit $offset, $numpage";
    $result = $db->sql_query($sql);
    
    echo"<br>";
    echo "<table border=\"1\" style=\"BORDER-COLLAPSE: collapse\"  borderColor=\"#008000\"   cellpadding=\"2\" cellspacing=\"0\" width=\"100%\">";
    echo "<tr bgcolor=\"#008000\"><td align=\"center\"><font size=\"2\">"._SOHIEU."</font></td><td align=\"center\"><font size=\"2\">"._TOMTAT."</font> </td><td align=\"center\"><font size=\"2\">"._SENDDATE."</font></td></tr><tr>";
    if ($numrows = $db->sql_numrows($result) > 0) {
    while ($row = $db->sql_fetchrow($result)) {
    $p_pid = intval($row[pid]);
    $p_title = $row[title];
    $p_hometext = $row[hometext];
    $p_hometext = stripslashes(check_html($p_hometext, nohtml));
    $p_date = date("d/m/Y", $row["postdate"]);
    $url = $row[url];
    echo "<td width=\"20%\"><a style=\"TEXT-DECORATION: none\" href=modules.php?name=$module_name&go=page&pid=$p_pid>$font1 $p_title</font></a> &nbsp</td>";
    echo "<td width=\"60%\">$font2$p_hometext &nbsp</font><br>";
    if(!$url==""){
    echo "<p align=\"right\">".$font2._DOWLOAD."</font>:";
    echo "<a  style=\"TEXT-DECORATION: none\" href=\"$url\"><img src=\"modules/$module_name/images/dowload.bmp\" border=\"0\" ></a> ";
     }else echo "<p align=\"right\">&nbsp";
    if (!$p_pid=="") {
    	$pid=intval($p_pid);
    echo "&nbsp&nbsp".$font2._PRINTV."</font>:";
    echo "<a href=\"#\" onClick=\"MM_openBrWindow('modules.php?name=$module_name&file=printv&pid=$pid','','scrollbars=yes,width=640,height=500')\" onMouseOut=\"window.status=''; return true;\" onMouseOver=\"window.status='"._PRINTV."'; return true;\"><img src=\"images/print.gif\" border=\"0\" alt=\""._PRINTV."\" title=\""._PRINTV."\" width=\"16\" height=\"16\"></a>\n";
        }
   echo "</p></td>";
    echo "<td width=\"15%\" align=\"right\">$font2$p_date &nbsp</font></td>";
    echo "</tr>";
         
    }
    echo "</table>";
    
    }
    #START Page Numbers
    $sql_pn = "select pid from ".$prefix."_vanban where  cid ='$cid' AND active = '1'";
    $result_pn = $db->sql_query($sql_pn);
    $numstories = $db->sql_numrows($result_pn);
    @$numpages = ceil($numstories / $numpage);
    if ($numpages > 1) {
        /****************************************/
        echo "<center>" ;
        if ($pagenum > 1) {
            $prevpage = $pagenum - 1 ;
                        $leftarrow = "images/left.gif" ;
                echo "<a href=\"modules.php?name=$module_name&amp;go=showcat&amp;cid=$cid&amp;pagenum=$prevpage\">";
                echo "<img src=\"$leftarrow\" align=\"absmiddle\" border=\"0\" hspace=\"10\"></a>";

        }
        for ($i=1; $i < $numpages+1; $i++) {

            if ($i == $pagenum) {
                echo "<b>$i</b>";
            }
            else {
            $pagelink = 10;
            if (($i > $pagenum) AND ($i < $pagenum+$pagelink) OR ($i < $pagenum) AND ($i > $pagenum-$pagelink)) {
            echo " <a href=\"modules.php?name=$module_name&amp;go=showcat&amp;cid=$cid&amp;pagenum=$i\">$i</a> ";
            }
            if (($i == $numpages) AND ($pagenum < $numpages-$pagelink)){
            echo "... <a href=\"modules.php?name=$module_name&amp;go=showcat&amp;cid=$cid&amp;pagenum=$i\">$i</a>";
            }
            if (($i == 1) AND ($pagenum > 1+$pagelink)){
            echo "<a href=\"modules.php?name=$module_name&amp;go=showcat&amp;cid=$cid&amp;pagenum=$i\">$i</a> ...";
            }
            }
        }
        if ($pagenum < $numpages) {
            $nextpage = $pagenum + 1 ;
                        $rightarrow = "images/right.gif" ;
                echo "<a href=\"modules.php?name=$module_name&amp;go=showcat&amp;cid=$cid&amp;pagenum=$nextpage\">";
                echo "<img src=\"$rightarrow\" align=\"absmiddle\" border=\"0\" hspace=\"10\"></a>";
        }
        echo "</center>" ;
        /****************************************/
    }
    #END Page Numbers
    /****************************************/
 
}
    

// Ket thuc http://sangkienvnpt.com



 switch($go) {

    case "cat":
    cat($cid);
    break;

    case "showcat":
    showcat($cid);
    break;

    case "page":
    page($pid, $page);
    break;

    default:
    main();
    break;

}


?>